<script>
    var switchId;
    function nextPage(pageNo){
        $("#team-listing").load("<?= $this->baseURI(); ?>marketing/team/list/0/"+pageNo);
    }
    function assignTeam(id){
        switchId = id;
        $("#assign-team-form").load("<?= $this->baseURI(); ?>marketing/team/add/"+switchId);
        $("#assign-team-form" ).dialog( "open" );
    }
    function editTeam(id){
        switchId = id;
        $("#edit-team-form").load("<?= $this->baseURI(); ?>marketing/team/edit/"+switchId);
        $("#edit-team-form" ).dialog( "open" );
    }
    $(function() {
        $( "#dialog:ui-dialog" ).dialog( "destroy" );
        $( "#assign-team-form" ).dialog({
            autoOpen: false,
            height: 300,
            width: 450,
            modal: true,
            buttons: {
                "Save": function() {
                    var bValid = true;
                    var price = $( "#contractPrice" );
                    var selectedUsers = $("#teamMembers").val() || [];
                    if ( bValid ) {
                        $.ajax({
                            type: "POST",
                            url: "<?= $this->baseURI(); ?>marketing/team/add/"+switchId,
                            data: ({contractPrice : price.val(),teamMembers:selectedUsers.join(",")}),
                            success: function(msg){
                                $("#notification-listing").load("<?= $this->baseURI(); ?>marketing/team/list");
                            }
                        });
                        $( this ).dialog( "close" );
                        $('#assign-team-form').html('');
                    }
                },
                Cancel: function() {
                    $( this ).dialog( "close" );
                    $('#assign-team-form').html('');
                }
            },
            close: function() {
                $('#assign-team-form').html('');
            }
        });
    });
</script>
<div class="dataBoxOver">
    <div class="dataInnRep">
        <div class="dataInnTop" id="team-listing">
            <?php echo $this->render('team/list.phtml'); ?>
        </div>
    </div>
</div>
<div id="assign-team-form" title="Assign Team"></div>
<div id="edit-team-form" title="Edit"></div>